package com.zxjbyte.yiyi.framework.oss.enums;

import cn.hutool.core.util.ArrayUtil;
import com.zxjbyte.yiyi.framework.common.core.ObjectArrayFactory;
import com.zxjbyte.yiyi.framework.oss.storage.OssConfig;
import com.zxjbyte.yiyi.framework.oss.storage.OssOperations;
import com.zxjbyte.yiyi.framework.oss.storage.db.DbOssConfig;
import com.zxjbyte.yiyi.framework.oss.storage.db.DbOssTemplate;
import com.zxjbyte.yiyi.framework.oss.storage.local.LocalOssConfig;
import com.zxjbyte.yiyi.framework.oss.storage.local.LocalOssTemplate;
import com.zxjbyte.yiyi.framework.oss.storage.s3.S3OssConfig;
import com.zxjbyte.yiyi.framework.oss.storage.s3.S3OssTemplate;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 对象存储器枚举
 * @Author zhangxingjia
 * @Date 2023/5/11 17:17
 * @Version: 1.0
 */
@AllArgsConstructor
@Getter
public enum OssStorageEnum implements ObjectArrayFactory {

    DB("S10001","数据库存储器", DbOssConfig.class, DbOssTemplate.class),

    LOCAL("S10002", "本地存储器", LocalOssConfig.class, LocalOssTemplate.class),

    S3("S10003", "s3协议云存储器", S3OssConfig.class, S3OssTemplate.class),
    ;

    /**
     * 存储器编号，要求唯一
     */
    private final String storageCode;

    /**
     * 描述
     */
    private final String des;

    /**
     * 配置类
     */
    private final Class<? extends OssConfig> configClass;

    /**
     * 模板类
     */
    private final Class<? extends OssOperations> templateClass;

    @Override
    public Object[] array() {
        return Arrays.stream(values()).map(OssStorageEnum::getStorageCode).toArray(String[]::new);
    }

    public static OssStorageEnum getByStorageCode(String storageCode) {
        return ArrayUtil.firstMatch(s -> s.getStorageCode().equals(storageCode), values());
    }
}
